home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / DialogBoxProxy.cpp < prev    next >
Text File  |  1997-09-08  |  6KB  |  246 lines

  1. /*
  2.  *  File:       DialogBoxProxy.cpp
  3.  *  Summary:       A stand in for TDialogBox that behaves better when it's being edited.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <1>     9/02/96    JDJ        Created
  12.  */
  13.  
  14. #include "DialogBoxProxy.h"
  15.  
  16. #include <List.h>
  17.  
  18. #include <ZAttribute.h>
  19. #include <ZStream.h>
  20. #include <ZStringUtils.h>
  21.  
  22. #include "Document.h"
  23. #include "ViewContainer.h"
  24. #include "WindowProxy.h"
  25.  
  26.  
  27. // ===================================================================================
  28. //    class CDialogBoxProxy
  29. // ===================================================================================
  30.  
  31. static TReanimatorRegister<CDialogBoxProxy> sDialogProxyRegistrar;
  32.  
  33. static TReanimatorRegister<CDialogBoxProxy> sDialogBoxRegistrar("TDialogBox");
  34.  
  35. //---------------------------------------------------------------
  36. //
  37. // CDialogBoxProxy::~CDialogBoxProxy
  38. //
  39. //---------------------------------------------------------------
  40. CDialogBoxProxy::~CDialogBoxProxy()
  41. {
  42.     // Delete the view container while we're still the right type.
  43.     this->DoDeleteSubPanes();
  44. }
  45.  
  46.  
  47. //---------------------------------------------------------------
  48. //
  49. // CDialogBoxProxy::CDialogBoxProxy ()
  50. //
  51. //---------------------------------------------------------------
  52. CDialogBoxProxy::CDialogBoxProxy() 
  53. {
  54.     this->AddAttribute("Editing", new TAttribute(kNonPersistant));
  55.  
  56.     CWindowProxy::msUseProxy = false;
  57. }
  58.  
  59.             
  60. //---------------------------------------------------------------
  61. //
  62. // CDialogBoxProxy::CDialogBoxProxy (SDialogBoxInfo, MCommander*)
  63. //
  64. //---------------------------------------------------------------
  65. CDialogBoxProxy::CDialogBoxProxy(const SDialogBoxInfo& info, MCommander* superCommander) : TDialogBox(info, superCommander)
  66. {
  67.     mOldAttributes = mAttributes;
  68.     
  69.     mAttributes.hasCloseBox   = true;
  70.     mAttributes.resizable     = true;
  71.     mAttributes.clickThrough  = true;
  72.     mAttributes.eraseOnUpdate = false;
  73.     mAttributes.layer         = kRegularLayer;
  74.  
  75.     this->SetDefaultButton(LoadAppString("OK"));            
  76.     this->SetCancelButton(LoadAppString("Cancel"));            
  77.  
  78.     this->AddAttribute("Editing", new TAttribute(kNonPersistant));
  79.  
  80.     CWindowProxy::msUseProxy = false;
  81. }
  82.  
  83.             
  84. //---------------------------------------------------------------
  85. //
  86. // CDialogBoxProxy::Create                                [static]
  87. //
  88. //---------------------------------------------------------------
  89. MReanimatable* CDialogBoxProxy::Create(MReanimatable*)
  90. {
  91.     if (CWindowProxy::msUseProxy)
  92.         return new CDialogBoxProxy;
  93.     else
  94.         return new TDialogBox;
  95. }
  96.  
  97.  
  98. //---------------------------------------------------------------
  99. //
  100. // CDialogBoxProxy::HandleClick
  101. //
  102. //---------------------------------------------------------------
  103. void CDialogBoxProxy::HandleClick(const TMouseEvent& globalEvent, short partCode)
  104. {
  105.     TRect sizeBox = mWindowPtr->portRect;
  106.     sizeBox.left = sizeBox.right - 15;
  107.     sizeBox.top = sizeBox.bottom - 15;
  108.         
  109.     TPoint localPt = this->PortToLocal(this->GlobalToPort(globalEvent.GetPosition()));
  110.  
  111.     if (sizeBox.Contains(localPt))
  112.         partCode = inGrow;
  113.         
  114.     Inherited::HandleClick(globalEvent, partCode);
  115. }
  116.  
  117.  
  118. //---------------------------------------------------------------
  119. //
  120. // CDialogBoxProxy::SetInfo
  121. //
  122. //---------------------------------------------------------------
  123. void CDialogBoxProxy::SetInfo(const SWindowInfo& info)
  124. {
  125.     Inherited::SetInfo(info);
  126.     
  127.     mOldAttributes = mAttributes;
  128.  
  129.     mAttributes.hasCloseBox   = true;
  130.     mAttributes.resizable     = true;
  131.     mAttributes.clickThrough  = true;
  132.     mAttributes.eraseOnUpdate = false;
  133.     mAttributes.layer         = kRegularLayer;
  134. }
  135.  
  136. #pragma mark ハ
  137.  
  138. //---------------------------------------------------------------
  139. //
  140. // CDialogBoxProxy::Invariant
  141. //
  142. //---------------------------------------------------------------
  143. void CDialogBoxProxy::Invariant() const
  144. {
  145.     Inherited::Invariant();
  146.     
  147.     if (mSubPanes->size() > 0) {
  148.         ASSERT(mSubPanes->size() == 1);
  149.         
  150.         TPane* subPane = mSubPanes->front();
  151.         ASSERT(subPane != nil);
  152.  
  153.         ASSERT(dynamic_cast<CViewContainer*>(subPane) != nil);
  154.     }
  155. }
  156.  
  157.  
  158. //---------------------------------------------------------------
  159. //
  160. // CDialogBoxProxy::OnStreamOut
  161. //
  162. //---------------------------------------------------------------
  163. void CDialogBoxProxy::OnStreamOut(TOutStream& stream) const
  164. {
  165.     CDialogBoxProxy* thisPtr = const_cast<CDialogBoxProxy*>(this);
  166.  
  167.     thisPtr->mAttributes = mOldAttributes;
  168.  
  169.     try {
  170.         Inherited::OnStreamOut(stream);
  171.         
  172.         thisPtr->mAttributes.hasCloseBox   = true;
  173.         thisPtr->mAttributes.resizable     = true;
  174.         thisPtr->mAttributes.clickThrough  = true;
  175.         thisPtr->mAttributes.eraseOnUpdate = false;
  176.         thisPtr->mAttributes.layer       = kRegularLayer;
  177.         
  178.     } catch (...) {
  179.         thisPtr->mAttributes.hasCloseBox   = true;
  180.         thisPtr->mAttributes.resizable     = true;
  181.         thisPtr->mAttributes.clickThrough  = true;
  182.         thisPtr->mAttributes.eraseOnUpdate = false;
  183.         thisPtr->mAttributes.layer       = kRegularLayer;
  184.         
  185.         throw;
  186.     }
  187. }
  188.  
  189.  
  190. //---------------------------------------------------------------
  191. //
  192. // CDialogBoxProxy::OnReanimated
  193. //
  194. //---------------------------------------------------------------
  195. void CDialogBoxProxy::OnReanimated()
  196. {
  197.     Inherited::OnReanimated();
  198.     
  199.     mOldAttributes = mAttributes;
  200.  
  201.     mAttributes.hasCloseBox   = true;
  202.     mAttributes.resizable     = true;
  203.     mAttributes.clickThrough  = true;
  204.     mAttributes.eraseOnUpdate = false;
  205.     mAttributes.layer         = kRegularLayer;
  206.     
  207.     TDesktop::Instance()->NormalizeWindowOrder();    
  208. }
  209.  
  210.  
  211. //---------------------------------------------------------------
  212. //
  213. // CDialogBoxProxy::OnOpen
  214. //
  215. //---------------------------------------------------------------
  216. void CDialogBoxProxy::OnOpen()
  217. {
  218.     Inherited::OnOpen();
  219.     
  220.     this->Show();
  221. }
  222.  
  223.  
  224. //---------------------------------------------------------------
  225. //
  226. // CDialogBoxProxy::DoClickInGrow
  227. //
  228. //---------------------------------------------------------------
  229. void CDialogBoxProxy::DoClickInGrow(const TMouseEvent& globalEvent)
  230. {
  231.     TSize oldSize = this->GetSize();
  232.     
  233.     Inherited::DoClickInGrow(globalEvent);
  234.     
  235.     TSize newSize = this->GetSize();
  236.     if (newSize != oldSize) {
  237.         CViewContainer* container = dynamic_cast<CViewContainer*>(mSubPanes->front());
  238.         
  239.         container->UpdateResource();
  240.     }        
  241. }
  242.  
  243.  
  244.  
  245.  
  246.